// 供热范围
// import { flatten as _flatten } from 'lodash';
// 废弃
// https://cdn.jsdelivr.net/npm/heatmap.js@2.0.5/build/heatmap.min.js
function SelfHeatMap({ map, whenCloseAll, heatPointsArr }) {
  if (!ol) { return }
  const ins = SelfHeatMap.getIns();
  if (ins) {
    return ins
  }
  this.mapIns = map;
  this.whenCloseAll = whenCloseAll;
  this.heatMapLayer = null;
  this.heatPointsArr = heatPointsArr;
  this.init();
  SelfHeatMap.ins = this;
}
SelfHeatMap.getIns = function () {
  return SelfHeatMap.ins;
}
SelfHeatMap.create = function ({ map, whenCloseAll, heatPointsArr }) {
  return new SelfHeatMap({ map, whenCloseAll, heatPointsArr })
}
// 销毁
SelfHeatMap.prototype.destroy = function () {
  if (!this.heatMapLayer) { return }
  this.mapIns.removeLayer(this.heatMapLayer);
  SelfHeatMap.ins = null;
}
// 显示隐藏切换
SelfHeatMap.prototype.toggle = function (tag) {
  if (!this.heatMapLayer) { return }
  this.heatMapLayer.setVisible(tag)
}
SelfHeatMap.prototype.build = function (data) {
}
// 初始化
SelfHeatMap.prototype.init = function () {
  //创建热力图
  const heatPointsArr = this.heatPointsArr;
  const heatPoints = [];
  const radius = 15;
  const blur = 50;
  for (let i = 0; i < heatPointsArr.length; i++) {
    const item = heatPointsArr[i];
    heatPoints[i] = new ol.Feature(new ol.geom.Point(item));
  }
  const heatMapLayer = new ol.layer.Heatmap({
    className: 'ol-layer-heatmap',
    source: new ol.source.Vector({
      features: heatPoints,
      wrapX: false
    }),
    blur: blur,
    radius: radius,
  });
  heatMapLayer.setZIndex(21)
  this.heatMapLayer = heatMapLayer;
  this.mapIns.addLayer(heatMapLayer);
}
export default SelfHeatMap;